import 'reflect-metadata'
function required(target, propertyKey) {
  console.log(target === User.prototype)
  Reflect.defineMetadata('required', true, target, propertyKey)
}
function validate(user) {
  for (let key in user) {
    if (Reflect.getMetadata('required', user, key) && !user[key]) {
      throw new Error(`属性${key}是必填项`)
    }
  }
}
class User {
  @required
  username: string
}
const user = new User()
user.username = '111'
validate(user)
